package com.proyecto.track.test;

import java.sql.Date;

import org.hibernate.Session;
import org.hibernate.Transaction;

import com.proyecto.track.bo.Account;
import com.proyecto.track.bo.Period;
import com.proyecto.track.bo.Project;
import com.proyecto.track.bo.ProjectStatus;
import com.proyecto.track.bo.ProjectUser;
import com.proyecto.track.bo.Rol;
import com.proyecto.track.bo.Task;
import com.proyecto.track.bo.TaskStatus;
import com.proyecto.track.bo.TaskType;
import com.proyecto.track.bo.UserPerson;
import com.proyecto.track.bo.UserTask;
import com.proyecto.track.bo.UserType;

public class CargarBaseDeDatos {

	/**
	 * @param args
	 */
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction transaction = session.beginTransaction();
		
		/* Project Status*/
		
		ProjectStatus projectStatus01 = new ProjectStatus("New");
		ProjectStatus projectStatus02 = new ProjectStatus("In progress");
		ProjectStatus projectStatus03 = new ProjectStatus("Finished");
		
		session.save(projectStatus01);
		session.save(projectStatus02);
		session.save(projectStatus03);
		
		/* Task Status*/
		
		TaskStatus taskStatus01 = new TaskStatus("New");
		TaskStatus taskStatus02 = new TaskStatus("In progress");
		TaskStatus taskStatus03 = new TaskStatus("Finished");
		
		session.save(taskStatus01);
		session.save(taskStatus02);
		session.save(taskStatus03);
		
		/* Task Type*/
		
		TaskType taskType01 = new TaskType("Analysis");
		TaskType taskType02 = new TaskType("Coding");
		TaskType taskType03 = new TaskType("QA");
		TaskType taskType04 = new TaskType("Testing");

		session.save(taskType01);
		session.save(taskType02);
		session.save(taskType03);
		session.save(taskType04);
		
		/* Users and Accounts*/
		
		UserType userType01 = new UserType("Project Leader");
		UserType userType02 = new UserType("Coder");
		UserType userType03 = new UserType("Tester");
		UserType userType04 = new UserType("QA Analyst");
		
		session.save(userType01);
		session.save(userType02);
		session.save(userType03);
		session.save(userType04);
		
		UserPerson userPerson01 = new UserPerson("juan@gmail.com", "Juan", "Diaz");
		Account account01 = new Account();
		account01.setPassword("1234");
		account01.setUserName("juanx");
		account01.setEnabled(true);
		userPerson01.setAccount(account01);
		userPerson01.setUserType(userType01);
			
		UserPerson userPerson02 = new UserPerson("pedro@gmail.com", "Pedro", "Diaz");
		Account account02 = new Account();
		account02.setPassword("1234");
		account02.setUserName("pedrox");
		account02.setEnabled(true);
		userPerson02.setAccount(account02);
		userPerson02.setUserType(userType02);
		
		UserPerson userPerson03 = new UserPerson("maria@gmail.com", "Maria", "Perez");
		Account account03 = new Account();
		account03.setPassword("1234");
		account03.setUserName("mariax");
		account03.setEnabled(true);
		userPerson03.setAccount(account03);
		userPerson03.setUserType(userType02);
		
		UserPerson userPerson04 = new UserPerson("jose@gmail.com", "Jose", "Gonzales");
		Account account04 = new Account();
		account04.setPassword("1234");
		account04.setUserName("josex");
		account04.setEnabled(true);
		userPerson04.setAccount(account04);
		userPerson04.setUserType(userType02);
		
		UserPerson userPerson05 = new UserPerson("juliana@gmail.com", "Juliana", "Bean");
		Account account05 = new Account();
		account05.setPassword("1234");
		account05.setUserName("julianax");
		account05.setEnabled(true);
		userPerson05.setAccount(account05);
		userPerson05.setUserType(userType03);
		
		session.save(userPerson01);
		session.save(userPerson02);
		session.save(userPerson03);
		session.save(userPerson04);
		session.save(userPerson05);
		
		/* Projects */
		
		Project project01 = new Project("Project Alpha", 240.00);
		project01.setLeader(userPerson01);
		project01.setProjectStatus(projectStatus01);
		
		ProjectUser projectUser01 = new ProjectUser(true, null);
		projectUser01.setProject(project01);
		projectUser01.setUserPerson(userPerson01);
		
		ProjectUser projectUser02 = new ProjectUser(true, null);
		projectUser02.setProject(project01);
		projectUser02.setUserPerson(userPerson02);
		
		ProjectUser projectUser03 = new ProjectUser(true, null);
		projectUser03.setProject(project01);
		projectUser03.setUserPerson(userPerson03);
		
		project01.getProjectUsers().add(projectUser01);
		project01.getProjectUsers().add(projectUser02);
		project01.getProjectUsers().add(projectUser03);

		session.save(project01);
				
		/*Task*/
		
		Task task01 = new Task("First Task", "Defines the requirements for the first task", 200.00);
		Period period = new Period();
		task01.setTaskStatus(taskStatus01);
		task01.setTaskType(taskType01);
		task01.setPeriod(period);
		
		UserTask userTask01 = new UserTask(70.00, 200.00, true);
		userTask01.setTask(task01);
		userTask01.setUserPerson(userPerson02);
		
		task01.getUserTasks().add(userTask01);
		
		Task task02 = new Task("First Task Coding", "Implements the definition specified in the First Task", 40.00);
		task02.setTaskStatus(taskStatus01);
		task02.setTaskType(taskType02);
		task02.setPeriod(period);
		UserTask userTask02 = new UserTask(00.00, 40.00, true);
		userTask02.setTask(task02);
		userTask02.setUserPerson(userPerson03);
		
		task02.getUserTasks().add(userTask02);
		
		session.save(task01);
		session.save(task02);
		
		project01.getTasks().add(task01);
		project01.getTasks().add(task02);
		
		session.update(project01);
		
		/*ROL*/
		
		Rol rol1 = new Rol();
		rol1.setName("ROL_ADMIN");
		
		
		Rol rol2 = new Rol();
		rol2.setName("ROL_USER");
		
		session.save(rol1);
		session.save(rol2);

		account01.setRol(rol1);
		account02.setRol(rol1);
		account03.setRol(rol1);
		account04.setRol(rol1);
		account05.setRol(rol2);
		
		session.update(account01);
		session.update(account02);
		session.update(account03);
		session.update(account04);
		session.update(account05);


		
		transaction.commit();
		session.close();

	}

}
